home *** CD-ROM | disk | FTP | other *** search
/ Network PC / Network PC.iso / windows 95 utilities / www browsers / netscape / update.exe / install.js < prev   
Text File  |  1997-06-23  |  15KB  |  416 lines

  1. /*  Mac, Win, Unix, everything.
  2. if (OSFlavor.substring(0,3) != "Win") {
  3.     updateStatusText(5, "This installer is not designed for a non-windows platform.  Please locate the correct installer.  Exiting.", 7, true, errorGraphic) ;
  4.     abortMe() ;
  5.     }
  6.  
  7. To figure out communicator version look here:
  8.       var Comm_vi = netscape.softupdate.Trigger.GetVersionInfo("Program/netscape.exe") ;
  9. */
  10.  
  11.  
  12. function checkJava() 
  13.     {
  14.     javaOn = navigator.javaEnabled() ; //check to see if java is enabled - nothing here works without it.
  15.     if (javaOn == false)
  16.         {
  17.         alert("You do not have java turned on, please enable Java, restart, and try again") ;
  18.         return false ;
  19.         }
  20.     return true ;
  21.     } 
  22.  
  23. function checkASD() 
  24.     {
  25.     SUEnabled = netscape.softupdate.Trigger.UpdateEnabled() ;  // SmartUpdate won't work without it being on.
  26.     if (SUEnabled == false)
  27.         {
  28.         alert("AutoInstall is not turned on in Advanced Preferences, please enable it, restart, and try again") ;
  29.         return false ;
  30.         }
  31.     return true ;
  32.     } 
  33.  
  34.  
  35. function verifyOS(val) // val should be a digit either 16 or 32, passed as a string.
  36.     {
  37.  
  38.     OS = navigator.platform ;
  39.     i = OS.substring(5,3) ;
  40.     if ( i != val)  
  41.         {
  42.         alert("Sorry, the install you are downloading doesn't support your operating system.  Install will not continue") ;
  43.         return false ;
  44.         }
  45.     return true ;
  46.     } 
  47.  
  48.  
  49. function checkNav()
  50.     {
  51.     
  52.     navVer = navigator.appVersion ;
  53.     
  54.     if (navVer.substring(0,4) == "4.01")
  55.         {
  56.         alert("You have already upgraded your Communicator to 4.01.  Install is not necessary.") ;
  57.         return false ;
  58.         }
  59.  
  60.  
  61.     if (navVer.substring(0,4) != "4.0 ")
  62.         {
  63.         alert("Sorry, you must have Communicator 4.0 (not beta) in order to upgrade.  Install will not continue") ;
  64.         return false ;
  65.         }
  66.  
  67.     return true ;
  68.     }
  69.  
  70. function checkLang()
  71.     {
  72.  
  73.     if (navigator.language != "en")
  74.         {
  75.         alert("Sorry, you must have Communicator 4.0 in English in order to upgrade.  Install will not continue") ;
  76.         return false ;
  77.         }
  78.     return true ;
  79.     }
  80.  
  81.  
  82.  
  83. function fileInfoObject(fileName, fileDestFolder, fileSourcePath, fileVersion, fileLocalPath ) {
  84.         this.fileName = fileName ;
  85.         this.fileDestFolder = fileDestFolder ;
  86.         this.fileSourcePath = fileSourcePath ;
  87.         this.fileVersion = fileVersion ;  
  88.         this.fileLocalPath = fileLocalPath ;
  89.         }
  90.  
  91.  
  92. function setupWindows()
  93.     {
  94. // just for clienteng release
  95.         wndw= window.open("","installer","toolbar=0,menubar=0,status=0,directories=0,location=0,scrollbars=0,resizable=0,width=480,height=400,top=50,left=100");
  96.                          // get the users' screen size
  97.         ScreenSize();     // another object made by us (See Below).
  98.         wndw.moveTo(width/2-250, height/2-200);          //center the window now that we know the dims.
  99.         wndw.document.open("text/html");                   //open a window that has the text/html mime type.
  100.         wndw.document.close() ;  // flush to window.
  101.         wndw.document.write("<TITLE>"+topWindowTitle+"</TITLE><center><br><br><h2>Please Wait...</h2></center>") ;
  102.         wndw.document.close() ;  // flush to window.        
  103.         // WRITE OUT THE HTML TO THE WINDOW, CREATING THE FRAMESET
  104.         line = "<TITLE>"+topWindowTitle+"</TITLE><FRAMESET ROWS='30%, 40%, *' border=0 frameborder='no' marginwidth=0><FRAME SRC='about:blank' NAME='TOP'> <FRAME SRC='about:blank' NAME='MIDDLE'> <FRAME SRC='about:blank' NAME='BOTTOM'></FRAMESET>" ;
  105.         wndw.document.write(line);
  106.         wndw.document.close() ;  // flush to window.
  107.  
  108. // an effort to clean the window of background info.
  109. wndw.frames[0].document.write("<center><br><br><h3>Please Wait...</h3></center>") ;
  110. wndw.frames[0].document.close() ;  //clean the window first.
  111.  
  112. wndw.frames[1].document.write("<center><br><br><h3>Please Wait...</h3></center>") ;
  113. wndw.frames[1].document.close() ;  //clean the window first.
  114.  
  115. wndw.frames[2].document.write("<center><br><br><h3>Please Wait...</h3></center>") ;
  116. wndw.frames[2].document.close() ;  //clean the window first.
  117.  
  118.  
  119.         line="<HTML><BODY><CENTER><H4>"+topWindowTitle+"</H4></CENTER></BODY></HTML>";
  120.         wndw.frames[0].document.close() ;  //clean the window first.
  121.         wndw.frames[0].document.write(line) ;
  122. // put text into the window first, then update it with a graphic.
  123.  
  124.         line="<HTML><BODY><CENTER><IMG SRC=http://home.netscape.com/inserts/images/n_sm.gif><H5>"+topWindowTitle+"</H5></CENTER></BODY></HTML>";
  125.         wndw.frames[0].document.close() ;  //clean the window first.
  126.         wndw.frames[0].document.write(line) ;
  127.  
  128.         updateStatusText(hSize, defaultText, 3, false, normalGraphic) ;
  129.     }
  130.  
  131.  
  132. function delay(amount) {
  133.     // init the values
  134.     var time = new Date() ;
  135.     var seconds = time.getSeconds() ;
  136.     var startCount = 80 ;
  137.     var newSeconds = 70 ;
  138.     //-------------------
  139.     startCount = (seconds + amount ) % 60 ;
  140.     time = new Date() ;
  141.     newSeconds = time.getSeconds() ;
  142.     while (newSeconds != startCount ) {
  143.         time = new Date() ;
  144.         newSeconds = time.getSeconds() ;
  145.         }
  146.  }
  147.  
  148.  
  149.  
  150. function ScreenSize()
  151.     {
  152.       if (navigator.javaEnabled())    // if Enable Java checkbox is checked then we can do the rest...
  153.       {
  154.          var tools=java.awt.Toolkit.getDefaultToolkit(); // tools object now exists and we can use 'em
  155.          var size=tools.getScreenSize();    // Identify the users' screen size.
  156.          width=size.width;                    //on-the-fly declaration of global variable width
  157.          height=size.height;                //on-the-fly declaration of global variable height
  158.       }
  159.     }
  160.  
  161.  
  162. function updateStatusText(hSize, text, delayTime, debugState, graphic )
  163.     {
  164.         if (debugState == true) {
  165.             java.lang.System.out.println(text) ;        
  166.             }
  167.         if (!silentValue) {
  168.             wndw.frames[1].document.close() ;
  169.             line="<HTML><BODY><CENTER><FONT FACE='Arial, Helvetica' SIZE=5 COLOR=BLUE><BR><H"+hSize+">"+text+"</H"+hSize+"><BR></CENTER></BODY></HTML>";
  170.             wndw.frames[1].document.close() ;  //clean the window first.
  171.             wndw.frames[1].document.write(line) ;
  172.             wndw.frames[1].document.close() ;  //clean the window first.
  173.  
  174.             if (graphic != "") {
  175.                 if (graphic == normalGraphic)
  176.                     line="<HTML><BODY><CENTER><IMG WIDTH=360 SRC="+graphic+"></CENTER></BODY></HTML>" ;
  177.                 if (graphic == errorGraphic)
  178.                     line="<HTML><BODY><CENTER><IMG HEIGHT=100 SRC="+graphic+"></CENTER></BODY></HTML>" ;
  179.                 wndw.frames[2].document.close() ;  //clean the window first.
  180.                 wndw.frames[2].document.write(line) ;
  181.                 wndw.frames[2].document.close() ;  //clean the window first.
  182.                 }
  183.  
  184.             if (delayTime != 0)    delay(delayTime) ;
  185.  
  186.         }
  187.     }
  188.  
  189.  
  190.  
  191.  
  192.  
  193. function abortMe() {
  194.             // check here for what the error numbers are.
  195.             java.lang.System.out.println("Installer error: " + err) ;
  196.             if (!silentValue) { 
  197.                 wndw.close() ;
  198.                 }
  199.  
  200.             su.AbortInstall() ;
  201.             errorFlag = true ;
  202. }
  203.  
  204.  
  205.  
  206. function errorParse(err) {
  207.     switch (err) {
  208.         case -210 :
  209.             updateStatusText(4, "Install cancelled! Exiting installation...", 5, true, errorGraphic) ;
  210.             break ;
  211.         case -201 :
  212.             updateStatusText(4, "Privileges not granted, Exiting...", 5, true, errorGraphic) ;
  213.             break ;
  214.         case -200 :
  215.             updateStatusText(4, "ERROR! Incorrect / Bad install package name.  Exiting...", 5, true, errorGraphic) ;
  216.             break ;
  217.         case -202 :
  218.             updateStatusText(4, "ERROR! Access denied.  Cannot write to system.  Exiting...", 5, true, errorGraphic) ;
  219.             break ;
  220.         case -203 :
  221.             updateStatusText(4, "ERROR! Too many certificates, only 1 is allowed. Exiting...", 5, true, errorGraphic) ;
  222.             break ;
  223.         case -204 :
  224.             updateStatusText(4, "ERROR! No installer certificate found! Exiting...", 5, true, errorGraphic) ;
  225.             break ;
  226.         case -205 :
  227.             updateStatusText(4, "ERROR! Extracted file is not signed. Exiting...", 5, true, errorGraphic) ;
  228.             break ;
  229.         case -206 :
  230.             updateStatusText(4, "ERROR! Extracted file does not match installer certificate. Exiting...", 5, true, errorGraphic) ;
  231.             break ;
  232.         case -207 :
  233.             updateStatusText(4, "ERROR! Jar file hasn't been opened/found. Exiting...", 5, true, errorGraphic) ;
  234.             break ;
  235.         case -208 :
  236.             updateStatusText(4, "ERROR! Error calling function (bad arguments). Exiting...", 5, true, errorGraphic) ;
  237.             break ;
  238.         case -209 :
  239.             updateStatusText(4, "ERROR! Illegal relative path to destination. Exiting...", 5, true, errorGraphic) ;
  240.             break ;
  241.         case -211 :
  242.             updateStatusText(4, "ERROR! Install never started. Exiting...", 5, true, errorGraphic) ;
  243.             break ;
  244.         case -20 :
  245.             updateStatusText(4, "ERROR, trying to setupFiles.", 4, true, errorGraphic) ;
  246.             break ;
  247.         case -1 :
  248.             updateStatusText(4, "ERROR, Adding components to the install.", 4, true, errorGraphic) ;
  249.             break ;
  250.         case -2 :
  251.             updateStatusText(4, "ERROR: Install not approved.  Exiting...", 4, true, errorGraphic) ;
  252.             break ;
  253.         case -3 :
  254.             updateStatusText(4, "ERROR: This installer is for 32 bit Windows only.  Exiting...", 4, true, errorGraphic) ;
  255.             break ;
  256.  
  257.         default :
  258.             updateStatusText(4, "an install error has occurred. Exiting...", 5, true, errorGraphic) ;
  259.         } //endswitch
  260. } //end errorParse
  261.  
  262. //*************************** END OF HEADER FILE ****************************
  263.  
  264.  
  265. function updateRegistry() {
  266.  
  267. var result = 0 ;
  268. fWinSystem = su.GetFolder("Win System") ;
  269. fCommunicator = su.GetFolder("Communicator") ;
  270. fWindows = su.GetFolder("Windows") ;
  271. winreg = su.GetWinRegistry() ;
  272. iniFile = su.GetWinProfile(fWindows, "system.ini") ;
  273. //Notes:
  274. // can't use a double backslash before subkey - Windows already puts it in.            
  275. //subkeys have to exist before values can be put in.
  276. //You can create subkeys all at once however.
  277. //---------------------------------------------
  278.  
  279. //Setup default Win registry stuff:
  280. // CREATE KEYS
  281. return err ;
  282. }
  283.  
  284. function buildArray() //stores the information for each file in the array.
  285.     {
  286. //Build used folder list here:
  287. fPlugins = su.GetFolder("Plugins") ;
  288. //fProgram = su.GetFolder("Program") ;
  289. //fJavaBin = su.GetFolder("Netscape Java Bin") ;
  290. //fJavaClasses = su.GetFolder("Netscape Java Classes") ;
  291. //fWinSystem = su.GetFolder("Win System") ;
  292. //fWindows = su.GetFolder("Windows") ;
  293. //fCommunicator = su.GetFolder("Communicator") ;
  294. // check folders before using them.
  295.  
  296. return err ;
  297. }
  298. // -----------------------------------------------------
  299.  
  300. function checkSystemEnvironment()  // OS check, memcheck, etc go here.
  301.     {
  302.     vi = new netscape.softupdate.VersionInfo(versionMaj, versionMin, versionRel, versionBld) ;
  303.     if (vi == null ) java.lang.System.out.println("new vi RETURNED NULL!") ;
  304.     return err ;
  305. }
  306.  
  307. function setupFiles(su){
  308.     var errFlag = false ; // to catch errors inside the addsubcomponent loops.
  309.  
  310.     updateStatusText(5, "Checking install privileges.  Click 'grant' if you are asked to approve the installation in the Java Security dialog.", 1, false, normalGraphic) ;    
  311. // clean up window from redraw problem
  312.     wndw.frames[0].document.close() ;  //clean the window first.
  313.     wndw.frames[1].document.close() ;  //clean the window first.
  314.     err = su.StartInstall(nsRegName, // Package name for registry
  315.                             vi,
  316.                             1);  //new api 1= full install
  317.     if (err !=0){
  318.         updateStatusText(hSize,"ERROR at StartInstall...", 4, true, errorGraphic) ;
  319.         return err ;
  320.         }
  321.     updateStatusText(hSize,"Extracting Install Files...", 1, false, normalGraphic) ;
  322.  
  323.     err = su.Execute("c32e401.exe") ;
  324.     return 0;
  325. }
  326.  
  327. function body() {    //this section works in clumps - each clump gets an error check after it's called.
  328.                     // the errorFlag is there to make sure I only call abortMe once.
  329.     if ( (su != null) )
  330.         {
  331.         updateStatusText(5,"You have started a process to upgrade Netscape Communicator from 4.0 to 4.01.", 8, false, "") ;
  332.         updateStatusText(5,"This new <I>SmartUpdate</I> technology will automatically launch another installer which will complete this process.", 8, false, "") ;
  333.         updateStatusText(5,"It is recommended that you not interrupt the install process until it is completed.",8, false, "") ;
  334.         err = checkSystemEnvironment() ;  //checksystemenvironments, if it returns error, abort
  335.         if (( err != 0 ) && (errorFlag == false)) 
  336.                 abortMe() ;
  337.  
  338.         if (err == 0) {        
  339.             updateStatusText(hSize,"Setting up external installer...", 1, false, "") ;
  340.             err = setupFiles(su) ;          // and abort.
  341.             if (( err != 0 ) && (errorFlag ==false)) {
  342.                 errorParse(err) ;
  343.                 abortMe() ;
  344.                 }
  345.             }
  346.  
  347.         if (err == 0)             // if we get to here, everythings cool and we can finalize install.
  348.             {
  349.             updateStatusText(5,"Please click 'Install' to launch external installer, or 'Cancel' to abort in the SmartUpdate window...", 0, false, "") ;   
  350.             err = su.FinalizeInstall();    // This actually copies all the files to their right place
  351.             if ((err == 999) || (err == 6)) err = 0 ; // Reboot is required, & parameter error- don't report as an error.
  352.             if (( err != 0 ) && (errorFlag ==false)) {
  353.                 errorParse(err) ;
  354.                 abortMe() ;
  355.                 }
  356.             }
  357.             
  358.         if (( err != 0 ) && (errorFlag ==false))    // If we have an error, write it to the console
  359.             {
  360.             errorParse(err) ;
  361.             abortMe() ;
  362.             }
  363.  
  364.         if (err == 0)
  365.             {
  366.             updateStatusText(3, "External Installer launched successfully!  Exiting...", 2, false, "") ;   
  367.             wndw.close() ;
  368.             }
  369.     }// endif
  370. }
  371.  
  372. // ================ START ================
  373. // this installer handles both Win16 and Win32 platforms
  374. if (checkNav() && verifyOS("32") && checkLang() && checkJava() && checkASD())
  375. {
  376.     //--- PRE FLIGHT CHECKS ------
  377.     var dbg = java.lang.System.out.println ;
  378.     var chkOS ;
  379.     var chkOSNum ;
  380.     var OSFlavor ;
  381.     chkOS = java.lang.System.getProperty("os.name") ;
  382.     chkOSNum = java.lang.System.getProperty("os.version") ;
  383.     OSFlavor = navigator.platform ;
  384.     
  385.     // VARIABLE DECLARATIONS
  386.     var nsRegName = "" ;
  387.     var updateObjectName = "Communicator 4.01 upgrade" ;
  388.     var topWindowTitle = "Netscape "+updateObjectName+" Installer" ;
  389.     var defaultText = "Initializing Installer..." ;
  390.     var text = "default text" ;  // string container for status update messages in bottom frame.
  391.     var err = 0 ;
  392.     var hSize = "4" ;
  393.     var su = null ;
  394.     var suEnv = this ;
  395.     var errorFlag = false ;
  396.     var versionMaj = 4 ;
  397.     var versionMin = 01 ;
  398.     var versionRel = 0 ;
  399.     var versionBld = 2 ;
  400.     var delayTime = 1 ;
  401.     var debugState = true ;
  402.     var graphic = "" ;
  403.     var errorGraphic = "http://home.netscape.com/download/images/mozilla_bungee.gif" ;
  404.     var normalGraphic = "http://home.netscape.com/download/images/mozilla_hurdles.gif" ;
  405.     var silentValue = false ;  // = this.silent ;
  406.     //======================================================
  407.     
  408.     if (!silentValue) setupWindows() ;
  409.     updateStatusText(hSize,"Starting the install...",1, true, normalGraphic) ;
  410.     su = new netscape.softupdate.SoftwareUpdate( this, updateObjectName ) ;
  411.     
  412.     if (su == null) updateStatusText(hSize,"Failed to create new softupdate obj.",1, true, errorGraphic) ;
  413.     
  414.     body() ;
  415.     
  416. } // end of check for java and ASD enabled.